package com.ruoyi.mobile.project.pms.service;

import com.github.pagehelper.PageHelper;
import com.ruoyi.db.pms.domain.PmsIssue;
import com.ruoyi.db.pms.domain.query.PmsIssueQueryVo;
import com.ruoyi.db.pms.mapper.PmsIssueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WxPmsIssueService
{
    @Autowired
    private PmsIssueMapper issueMapper;

    /**
     * 删除商品问题
     *
     * @author 张涛
     * @param id
     */
    public void deleteById(Long id)
    {
        issueMapper.deletePmsIssueById(id);
    }

    /**
     * 添加商品问题
     *
     * @author 张涛
     * @param issue
     */
    public void add(PmsIssue issue)
    {
        issue.setAddTime(LocalDateTime.now());
        issue.setUpdateTime(LocalDateTime.now());
        issueMapper.insertPmsIssue(issue);
    }

    /**
     * 获取商品问题列表
     *
     * @author 张涛
     * @param question
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    public List<PmsIssue> querySelective(String question, Integer page, Integer limit, String sort, String order)
    {
        PmsIssueQueryVo pmsIssueQueryVo = new PmsIssueQueryVo();
        if (!StringUtils.isEmpty(question)) {
            pmsIssueQueryVo.setQuestion(question);
        }

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            pmsIssueQueryVo.setSort(sort);
            pmsIssueQueryVo.setOrder(order);
        }

        PageHelper.startPage(page, limit);
        return issueMapper.selectPmsIssueList(pmsIssueQueryVo);
    }

    /**
     * 修改商品问题
     *
     * @author 张涛
     * @param issue
     */
    public int updateById(PmsIssue issue)
    {
        issue.setUpdateTime(LocalDateTime.now());
        return issueMapper.updatePmsIssue(issue);
    }

    /**
     * 根据id获取某一商品问题
     *
     * @author 张涛
     * @param id
     * @return
     */
    public PmsIssue findById(Long id)
    {
        return issueMapper.selectPmsIssueById(id);
    }
}
